﻿using MTUnity.Utils;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class FExterior : DataBase
{
    public override void InvalidDataCheck(string str)
    {
        base.InvalidDataCheck(str);
    }
}

public class FOverView : DataBase
{
    //7-14
    private List<FVisitorRecord> m_listVisitorRecord = new List<FVisitorRecord>();
    //6-12
    private List<FAirPressureRecord> m_listAirPressureRecord = new List<FAirPressureRecord>();
    //6-12
    private List<FVoltageRecord> m_listVoltageRecord = new List<FVoltageRecord>();

    public FCurrentVisitor CurrentVisitor = new FCurrentVisitor();

    public double CurrentAirPressure { get; set; }
    public double CurrentVoltage { get; set; }

    public void AddVisitorRecordData(int iVisitorCount , long lTimestamp)
    {
        m_listVisitorRecord.Add(new FVisitorRecord()
        {
            VisitorCount = iVisitorCount,
            Timestamp = lTimestamp
        });
    }

    public void AddAirPressureRecordData(double dAirPressureCount, long lTimestamp)
    {
        m_listAirPressureRecord.Add(new FAirPressureRecord()
        {
            AirPressure = dAirPressureCount,
            Timestamp = lTimestamp
        });
    }
    public void AddVoltageRecordData(double dVoltageCount, long lTimestamp)
    {
        m_listVoltageRecord.Add(new FVoltageRecord()
        {
            Voltage = dVoltageCount,
            Timestamp = lTimestamp
        });
    }


    public List<FVisitorRecord> GetNearestVisitorRecordData(int iCount)
    {
        return ToolUtils.GetCountFromList<FVisitorRecord>(m_listVisitorRecord, iCount);
    }

    public List<FAirPressureRecord> GetNearestAirPressureRecordData(int iCount)
    {
        return ToolUtils.GetCountFromList<FAirPressureRecord>(m_listAirPressureRecord, iCount);
    }

    public List<FVoltageRecord> GetNearestVoltageRecordData(int iCount)
    {
        return ToolUtils.GetCountFromList<FVoltageRecord>(m_listVoltageRecord, iCount);
    }

    public override void InvalidDataCheck(string str)
    {
        switch (str)
        {
            case JsonFildName.OverView.Record_Visitor:
                ToolUtils.LimitListMaxCount<FVisitorRecord>(m_listVisitorRecord, RecordCount.RecordVisitor_2);
                break;
            case JsonFildName.OverView.Record_AirPressure:
                ToolUtils.LimitListMaxCount<FAirPressureRecord>(m_listAirPressureRecord, RecordCount.RecordAirPressure_2);
                break;
            case JsonFildName.OverView.Record_Voltage:
                ToolUtils.LimitListMaxCount<FVoltageRecord>(m_listVoltageRecord, RecordCount.RecordVoltage_2);
                break;
            default:
                ToolUtils.LimitListMaxCount<FVisitorRecord>(m_listVisitorRecord, RecordCount.RecordVisitor_2);
                ToolUtils.LimitListMaxCount<FAirPressureRecord>(m_listAirPressureRecord, RecordCount.RecordAirPressure_2);
                ToolUtils.LimitListMaxCount<FVoltageRecord>(m_listVoltageRecord, RecordCount.RecordVoltage_2);
                break;
        }
        base.InvalidDataCheck(str);
    }
}

public class FCurrentVisitor
{
    public enum EVisitorType
    {
        E_Total,
        E_Guest,
        E_Staff,
        E_Car
    }

    private Dictionary<EVisitorType, int> m_dicVisitorTypeData = new Dictionary<EVisitorType, int>();

    public void UpdateVisitorType(EVisitorType eVisitorType , int iCount)
    {
        if (m_dicVisitorTypeData.ContainsKey(eVisitorType))
        {
            m_dicVisitorTypeData[eVisitorType] = iCount;
        }
        else
        {
            m_dicVisitorTypeData.Add(eVisitorType, iCount);
        }
    }

    public int GetVisitorType(EVisitorType eVisitorType)
    {
        if (m_dicVisitorTypeData.ContainsKey(eVisitorType))
        {
           return m_dicVisitorTypeData[eVisitorType];
        }
        return 0;
    }
}

public struct FVisitorRecord
{
    public int VisitorCount { get; set; }
    public long Timestamp { get; set; }
}

public struct FAirPressureRecord
{
    public double AirPressure { get; set; }
    public long Timestamp { get; set; }
}

public struct FVoltageRecord
{
    public double Voltage { get; set; }
    public long Timestamp { get; set; }
}